package com.ruoyi.web.controller.cinema;

import java.util.List;

import com.ruoyi.cinema.mapper.FilmScheduleMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cinema.domain.FilmSchedule;
import com.ruoyi.cinema.service.IFilmScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 影片排期Controller
 *
 * @author HHAOYU
 * @date 2020-12-08
 */
@RestController
@RequestMapping("/cinema/schedule")
public class FilmScheduleController extends BaseController
{
    @Autowired
    private IFilmScheduleService filmScheduleService;
    @Autowired
    private FilmScheduleMapper filmScheduleMapper;

    /**
     * 查询影片排期列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:schedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(FilmSchedule filmSchedule)
    {
        startPage();
        List<FilmSchedule> list = filmScheduleMapper.selectFilmScheduleAdminList(filmSchedule);
        return getDataTable(list);
    }

    /**
     * 导出影片排期列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:schedule:export')")
    @Log(title = "影片排期", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FilmSchedule filmSchedule)
    {
        List<FilmSchedule> list = filmScheduleService.selectFilmScheduleList(filmSchedule);
        ExcelUtil<FilmSchedule> util = new ExcelUtil<FilmSchedule>(FilmSchedule.class);
        return util.exportExcel(list, "schedule");
    }

    /**
     * 获取影片排期详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:schedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(filmScheduleService.selectFilmScheduleById(id));
    }

    /**
     * 新增影片排期
     */
    @PreAuthorize("@ss.hasPermi('cinema:schedule:add')")
    @Log(title = "影片排期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilmSchedule filmSchedule)
    {
        return toAjax(filmScheduleService.insertFilmSchedule(filmSchedule));
    }

    /**
     * 修改影片排期
     */
    @PreAuthorize("@ss.hasPermi('cinema:schedule:edit')")
    @Log(title = "影片排期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FilmSchedule filmSchedule)
    {
        return toAjax(filmScheduleService.updateFilmSchedule(filmSchedule));
    }

    /**
     * 删除影片排期
     */
    @PreAuthorize("@ss.hasPermi('cinema:schedule:remove')")
    @Log(title = "影片排期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(filmScheduleService.deleteFilmScheduleByIds(ids));
    }
}
